package com.taichuan.keysupport;

import android.os.Handler;
import android.view.KeyEvent;

/**
 * Created by OISNY on 2016/8/18.
 */
public class KeySupport {

    Observer observer;
    private final Handler mHandler = new Handler() {

        public void handleMessage(android.os.Message msg) {
            if (observer != null) {
                KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN,
                        msg.arg2);
                observer.onInputKeyEvent(msg.arg1);
                observer.onConvertKeyEvent(msg.arg2, keyEvent);
            }
        }
    };

    public KeySupport(Observer observer) {
        this.observer = observer;
    }

    public void input(int inputKeyCode) {
        int keyCode = Key.convertKeyCode(inputKeyCode);
        mHandler.obtainMessage(0, inputKeyCode, keyCode).sendToTarget();
    }


}
